package com.example.twitter;


import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class Main extends Activity implements OnClickListener{
	Button boton;
	Button abrirNavegador;
	
	EditText et;
	TextView tx;
	
	ConfiguracionTwitter config;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		config = new ConfiguracionTwitter(this);
		if(config.ComprobarCredencialesLocales(this)){
			Intent i = new Intent(this, TimeLine.class);
			
			this.startActivity(i);
			this.finish();
		}
		setContentView(R.layout.main);
		
		boton = (Button) this.findViewById(R.id.boton);
		abrirNavegador = (Button) this.findViewById(R.id.AbrirNavegador);
		et = (EditText) this.findViewById(R.id.textViewTweet);
		tx = (TextView) this.findViewById(R.id.textView);
		
		
		
		boton.setOnClickListener(this);	
		abrirNavegador.setOnClickListener(this);
		
		
		
		
		
	}

	@Override
	public void onClick(View v) {
		if(v == boton){
			if(config.ComprobarPIN(et.getText().toString(), this)){
				tx.setText("Correcto");
				Context c = this;
				Intent i = new Intent(c, TimeLine.class);
				
				this.startActivity(i);
				this.finish();
			}
			else
				tx.setText("Incorrecto");
		}
		else if(v == abrirNavegador){
			Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(config.getURLAuthent()));
			startActivity(i);
		}
		
	}
	
	
	
	

	

	
}
